package cn.csc.module.distribute.controller.app.withdraw;

import cn.csc.framework.common.pojo.CommonResult;
import cn.csc.framework.common.pojo.PageResult;
import cn.csc.module.distribute.controller.app.withdraw.vo.AppDistributeWithdrawPageReqVO;
import cn.csc.module.distribute.controller.app.withdraw.vo.AppDistributeWithdrawReqVO;
import cn.csc.module.distribute.controller.app.withdraw.vo.AppDistributeWithdrawRespVO;
import cn.csc.module.distribute.convert.withdraw.DistributeWithdrawConvert;
import cn.csc.module.distribute.dal.dataobject.withdraw.DistributeWithdrawDO;
import cn.csc.module.distribute.service.withdraw.DistributeWithdrawService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.csc.framework.common.pojo.CommonResult.success;

/**
 * @author 云隐
 * @date 2025/4/23
 **/
@Api(tags = "APP用户 - 分销员提现")
@RestController
@RequestMapping("/distribute/withdraw")
@Validated
public class AppDistributeWithdrawController {

    @Resource
    DistributeWithdrawService distributeWithdrawService;

    /**
     * 申请提现
     */
    @PostMapping("/withdrawApply")
    @ApiOperation("申请提现")
    public CommonResult<Boolean> withdrawApply(@Valid @RequestBody AppDistributeWithdrawReqVO reqVO) {
        distributeWithdrawService.applyWithdraw(reqVO);
        return success(true);
    }


    /**
     * 获得提现记录
     * @param pageVO
     * @return
     */
    @GetMapping("/withdrawList")
    @ApiOperation("获得提现记录")
    public CommonResult<PageResult<AppDistributeWithdrawRespVO>> getWithdrawPage(AppDistributeWithdrawPageReqVO pageVO) {
        PageResult<DistributeWithdrawDO> pageResult = distributeWithdrawService.getAppWithdrawPage(pageVO);
        return success(DistributeWithdrawConvert.INSTANCE.convertPage1(pageResult));
    }

}
